#include "widget_class.h"

Widget_class::Widget_class()
{

}
Widget_class::Widget_class(QWidget *parent) : QWidget(parent)
{
    // 设定默认颜色
    background_color = QColor(204, 235, 255);  // 原始浅蓝色背景
    foreground_color = QColor(240, 249, 255);  // 更浅一些的颜色
    corner_radius = 15;
}

void Widget_class::set_background_color(QColor color)
{
    this->background_color = color;
    update(); // 触发重绘
}

void Widget_class::set_foreground_color(QColor color)
{
    this->foreground_color = color;
    update(); // 触发重绘
}

void Widget_class::set_corner_radius(int radius)
{
    this->corner_radius = radius;
    update(); // 触发重绘
}

void Widget_class::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    // 创建 QPainter 对象
    QPainter painter(this);

    // 启用抗锯齿效果，使绘制更加平滑
    painter.setRenderHint(QPainter::Antialiasing);

    // 获取控件的矩形区域
    QRect rect = this->rect();

    // 第一步：绘制背景（原始浅蓝色背景）
    QBrush background_brush(background_color);
    painter.setBrush(background_brush);
    painter.setPen(Qt::NoPen);
    painter.drawRoundedRect(rect, corner_radius, corner_radius);

    // 第二步：绘制前景圆角矩形（更深色的矩形）
    // 让前景矩形比背景稍微小一点，形成边框效果
    QRect foreground_rect = rect.adjusted(3, 3, -3, -3);

    QBrush foreground_brush(foreground_color);
    painter.setBrush(foreground_brush);
    painter.setPen(Qt::NoPen);
    painter.drawRoundedRect(foreground_rect, corner_radius - 2, corner_radius - 2);
}
